<?php
require_once 'application/library/db/gcDaoFactory.php';
require_once 'application/constant/daoConfig.php';
/**
 * 
 * goods_services_goodsFormulaService
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */

class goods_services_goodsFormulaService{

    private $objDaoFactory;

    public function __construct(){
        $this->objDaoFactory = gcDaoFactory::getInstance();
    }

    public function pbGetCount() {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $count = $objGoodsDao->pbGetCount();
        return $count;
    }

    public function pbInsertGoods($arrProductInfo) {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $strGoodsNo = $objGoodsDao->pbInsertGoods($arrProductInfo);
        return $strGoodsNo;
    }

    public function pbUpdateGoods($strGoodsNo, $arrProductInfo) {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $strUpdateRe = $objGoodsDao->pbUpdateGoods($strGoodsNo, $arrProductInfo);
        return $strUpdateRe;
    }

    public function pbInsertFormula($strGoodsNo, $strFormulaName) {
        $objFormulaDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_FORMULA_DAO);
        $strFormulaNo = $objFormulaDao->pbInsertFormula($strGoodsNo, $strFormulaName);
        return $strFormulaNo;
    }

    public function pbUpdateFomula($strFormulaNo, $strFormulaName) {
        $objFormulaDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_FORMULA_DAO);
        $strUpdateRe = $objFormulaDao->pbUpdateFomula($strFormulaNo, $strFormulaName);
        return $strUpdateRe;
    }
    public function pbInsertFormulaItem($arrFormulaGoodsInfo, $strFormulaNo) {
        $objFormulaItemDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_FORMULA_ITEM_DAO);
        foreach ($arrFormulaGoodsInfo as $key => &$value) {
            $value["FormulaNo"] = $strFormulaNo;
        }
        $insertRe = $objFormulaItemDao->pbInsertFormulaItem($arrFormulaGoodsInfo);
    }

    public function pbUpdateFormulaItem($strFormulaNo, $arrFormulaGoodsInfo) {
        $objFormulaItemDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_FORMULA_ITEM_DAO);
        $objFormulaItemDao->pbDeleteFormulaItem($strFormulaNo);
        foreach ($arrFormulaGoodsInfo as $key => &$value) {
            $value["FormulaNo"] = $strFormulaNo;
        }
        $insertRe = $objFormulaItemDao->pbInsertFormulaItem($arrFormulaGoodsInfo);
        return $insertRe;
    }
    public function pbGetFormulaItemInfo($strFormulaNo) {
        $objFormulaItemDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_FORMULA_ITEM_DAO);
        $arrFormulaItemInfo = $objFormulaItemDao->pbGetFormulaItemInfo($strFormulaNo);
        return $arrFormulaItemInfo;
    }

    public function pbGetFormulaInfo($strFormulaNo) {
        $objFormulaDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_FORMULA_DAO);
        $arrFormulaInfo = $objFormulaDao->pbGetFormulaInfo($strFormulaNo);
        return $arrFormulaInfo;
    }

    public function pbGetGoods($arrFormulaItemInfo) {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $arrGoods = $objGoodsDao->pbGetGoods();
        foreach($arrGoods as $key => &$value) {
            $value["SIMVARIATION"] = mb_substr($value["VARIATION"], 0, 10, "utf-8");
            $value["SIMNAME_GROUP"] = mb_substr($value["NAME_GROUP"], 0, 10, "utf-8");
            if($value["SUPPLIERNUM"] == null) {
                $value["SUPPLIERNUM"] = 0;
            } else {}
            if (!empty($arrFormulaItemInfo)) {
                foreach ($arrFormulaItemInfo as $j => $valuej) {
                    if($value["GOODS_NO"] == $valuej["GOODS_NO"]) {
                        $value["disableFlag"] = 1;
                    } else {
                    }
                }
            } else {}
        }
        return $arrGoods;
    }

    public function pbGetSearchCount($arrCondition) {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $count = $objGoodsDao->pbGetSearchCount($arrCondition);
        return $count;
    }

    public function pbSearchGoods($arrCondition, $arrGoodsId) {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $arrGoods = $objGoodsDao->pbSearchGoods($arrCondition);
        foreach($arrGoods as $key => &$value) {
            $value["SIMVARIATION"] = mb_substr($value["VARIATION"], 0, 10, "utf-8");
            $value["SIMNAME_GROUP"] = mb_substr($value["NAME_GROUP"], 0, 10, "utf-8");
            if($value["SUPPLIERNUM"] == null) {
                $value["SUPPLIERNUM"] = 0;
            } else {}
            if (!empty($arrGoodsId)) {
                foreach ($arrGoodsId as $j => $valuej) {
                    if($value["GOODS_NO"] == $valuej) {
                        $value["disableFlag"] = 1;
                    } else {
                    }
                }
            } else {}
        }
        return $arrGoods;
    }
}
